<template>
  <div>
    <van-picker
      title="设置性别"
      show-toolbar
      :columns="columns"
      :default-index="value"
      @confirm="onUpdetagender"
      @cancel="$emit('close')"
    />
  </div>
</template>

<script>
import { updateUserFile } from '@/api/user'
export default {
  data () {
    return {
      columns: ['男', '女']
    }
  },
  props: {
    value: {
      type: Number
    }
  },
  methods: {
    async onUpdetagender (val, index) {
      console.log(val)
      this.$toast.loading({
        message: '更新中...',
        forbidClick: true,
        duration: 0
      })
      try {
        await updateUserFile({
          gender: index
        })
        this.$toast('更新成功')
        this.$emit('input', index)
      } catch (err) {
        this.$toast('更新失败，请重试')
      }
    }
  }
}
</script>

<style lang="less" scoped>

</style>
